# 一个ThreadLocal变量虽然是全局变量，但每个线程都只能读写自己线程的独立副本，互不干扰。
# ThreadLocal解决了参数在一个线程中各个函数之间互相传递的问题。
import threading
student = threading.local()


class Student(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age


def _thread(name, age):
    student.name = name
    student.age = age
    _print(student)


def _print(people):
    print("Student %s is %s old!" % (people.name, people.age))


thread1 = threading.Thread(target=_thread, args=("Tom", 12))
thread2 = threading.Thread(target=_thread, args=("Jerry", 10))
thread1.start()
thread2.start()
thread1.join()
thread2.join()
